public class Date
{
    int year;
    int month;
    int day;
    public int GetMonthDay(int year,int month)//判断月份天数
    {
        int[] monthArray = { 0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};//将月份放到数组中，通过下标访问
        if (month == 2 && ((year % 4 == 0 && year % 100 != 0) || (year % 400 == 0)))//计算特殊的二月
        {
            return 29;
        }
        return monthArray[month];
    }
    public void Judge(int year, int month, int day) //检查日期是否合法
    {
    this.year = year;
    this.month = month;
    this.day = day;
    //检查日期是否合法
    if (month < 1 || month > 12 || day < 1 || day > GetMonthDay(year, month))
    {
        System.out.println("非法日期");
        System.exit(-1);//终止程序
    }
    else
    {
        System.out.println( this.year + "年" + this.month + "月"+ this.day + "日");
    }
    }
}
